<template>
	<view>
		<view class="u-p-30" >
			<u-table align="left" border-color="#fff">
				<u-tr class="u-tr" >
					<u-td class="u-td" width="160rpx">订单状态：</u-td>
					<u-td class="u-td">{{statusString}}</u-td>
				</u-tr>
				<u-tr class="u-tr" >
					<u-td class="u-td" width="160rpx">订单编号：</u-td>
					<u-td class="u-td">{{orderinfo.order_no}}</u-td>
				</u-tr>
				<u-tr class="u-tr" >
					<u-td class="u-td" width="160rpx">下单时间：</u-td>
					<u-td class="u-td">{{orderinfo.updated_at}}</u-td>
				</u-tr>
				<u-tr class="u-tr" >
					<u-td class="u-td" width="160rpx">支付金额：</u-td>
					<u-td class="u-td">￥ {{total}} 元</u-td>
				</u-tr>
				<u-tr class="u-tr" >
					<u-td class="u-td" width="160rpx">联系信息：</u-td>
					<u-td class="u-td">{{orderAddress.name}}  {{orderAddress.phone}}</u-td>
				</u-tr>
				<u-tr class="u-tr" >
					<u-td class="u-td" width="160rpx">配送地址：</u-td>
					<u-td class="u-td">{{orderAddress.province}}-{{orderAddress.city}}-{{orderAddress.county}} {{orderAddress.address}}</u-td>
				</u-tr>
				
			</u-table>
		</view>
		
		<!-- 订单列表 -->
		<view class="uni-list">
			
				<view class="car_home_foods">
					<view class="car_food_item" v-for="(item,index) in orderDetails" :key="item.id">
						
						<view class="car_food_info">
							<view class="car_food_img">
								<block v-if="item.goods">
									<image class="food_img" :src="item.goods.cover_url" mode="aspectFill"></image>
								</block>
								<block v-else>
									<image class="food_img default" src="@/static/default_good1.png" mode="aspectFill">
									</image>
								</block>
							</view>
							<view class="car_food_right">
								<view class="car_food_top">
									<view class="car_food_left">
										<view class="car_food_name">{{item.goods.title}}
										</view>
										<view class="car_food_label">{{item.goods.description}}</view>
									</view>
									<view class="car_edit_right">
										<view class="car_food_name">数量：{{item.num}}
										</view>
									</view>
								</view>
								<view class="car_food_bottom">
									<view class="car_food_price">
										￥ {{item.goods.price?parseFloat(item.goods.price).toFixed(2):'0.00'}}
									</view>
								
								</view>
							</view>
						</view>
					</view>
				</view>
		
		</view>
		<!-- 列表结束 --> 
		<view class="foot">
			
				<u-button type="primary" class="add" @click="onSubmit">马上支付</u-button>
				<u-button type="warning" class="add1" @click="onSubmit">确认收货</u-button>
		   
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				orderNo:'',
				orderinfo:{},				
				orderDetails:[],
				orderAddress:[],
			}
		},
		onLoad(option) {   //onLoad页面加载
			this.orderNo = option.id
			this.init()  //订单详情
		},
		methods: {
			async init(){
				const orderNo = this.orderNo
				const res = await this.$u.api.getOrderDetail(orderNo,{include:'orderDetails.goods,address'})
				console.log(res)
				this.orderinfo = res
				this.orderDetails = res.orderDetails.data
				this.orderAddress = res.address
				
				
			},
			
					
		},
		computed:{
			statusString(){
				//订单状态: 1下单 2支付 3发货 4收货 5过期
				let status = ['','已经下单','已经支付','等待发货','确认收货','已过期'];
				// console.log(this.orderinfo.status,'@@@')
				return status[this.orderinfo.status];	
			},
			total(){
				let sum =0;
				this.orderDetails.forEach(item=>{
					sum += item.num * item.price;
				})
				return sum+'.00';
			}
		}
	}
</script>

<style scoped lang="scss">
	.foot {
		margin-top: 30rpx;
		justify-content: space-around;
		width: 600rpx;
		line-height: 100rpx;
		position: sticky;
		bottom: 30rpx;
		left: 80rpx;
		background-color: #FF9900;
		border-radius: 60rpx;
		font-size: 30rpx;
		.add1{
			position:fixed;
			justify-content: space-around;
			width: 600rpx;
			margin-top: 20rpx;
			left: 80rpx;
			align-items: center;
			color: #ffffff;
	
		}
	}
.car_home_box {
		font-size: 24rpx;

		.all_select_box {
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 20rpx;
			box-sizing: border-box;
			font-size: 22rpx;
		}

		.car_home_name {
			display: flex;
			justify-content: flex-start;
			align-items: center;
			padding: 20rpx;
			box-sizing: border-box;

			view {
				font-weight: bold;
				font-size: 26rpx;
			}
		}
	}

	.car_home_foods {
		background-color: #ffffff;

		.car_food_item {
			display: flex;
			justify-content: flex-start;
			align-items: center;
			padding: 20rpx;
			box-sizing: border-box;
			border-bottom: 2rpx solid #eaeaea;

			&:last-of-type {
				border-bottom: 0;
			}

			.car_food_info {
				display: flex;
				justify-content: space-between;
				align-items: stretch;
				width: 100%;

				.car_food_img {
					width: 160rpx;
					height: 160rpx;
					border: 2rpx solid #dfe2e7;
					box-sizing: border-box;
					margin-right: 20rpx;
					border-radius: 10rpx;
					overflow: hidden;
					position: relative;

					.food_img {
						width: 100% !important;
						height: 100%;
						border-radius: 10rpx;
					}
				}

				.car_food_right {
					width: 72%;
					display: flex;
					flex-wrap: wrap;
					align-content: space-between;

					.car_food_top {
						width: 100%;
						display: flex;
						justify-content: space-between;
						align-items: flex-start;

						.car_food_left {
							width: 75%;

							.car_food_name {
								font-size: 20rpx;
								font-weight: bold;
								margin: 5rpx 0;
							}

							.car_food_remark {
								// color: #868ea4;
								// font-style: italic;
								font-size: 24rpx;
								margin-bottom: 5rpx;
							}

							.car_food_label {
								color: #7E7E7E;
								font-size: 20rpx;
								margin-bottom: 5rpx;
							}
						}

						.car_edit_right {
							display: flex;
							align-items: center;
							justify-content: flex-end;

							.car_edit_btn {
								color: #DB0E7E;
								font-size: 24rpx;
								font-weight: bold;
								font-smooth: Roboto;
								display: inline-block;
								padding: 5rpx 15rpx;
								border-radius: 30rpx;
								border: 1px solid #DB0E7E;
								margin-right: 20rpx;
							}

							.car_del_icon {
								width: 24rpx;
								height: 30rpx;
							}
						}

						text {
							font-weight: bold;
							font-size: 28rpx;
						}
					}

					.car_food_bottom {
						width: 100%;
						display: flex;
						justify-content: space-between;
						align-items: center;

						.car_food_price {
							color: #DB0E7E;
							font-size: 26rpx;
							font-weight: 500;

							text {
								color: #8E8E8E;
								font-size: 22rpx;
								text-decoration: line-through;
								margin-left: 15rpx;
								font-weight: 400;
							}
						}
					}
				}
			}
		}
	}
</style>
